<template>
  <div class='post-comment'>
    <van-field
      v-model="message"
      rows="2"
      autosize
      type="textarea"
      autofocus
      maxlength="50"
      placeholder="你想说点什么..."
      show-word-limit
    >
  </van-field>
  <van-button size="mini" @click="onPost">发布</van-button>
   </div>
</template>

<script>
  import bus from '@/utils/bus'
  import {addComment} from '@/api/comment'
export default {
  name: 'post-comment',
  components: {},
  props: {
    articleId: {
      type: [Number, String],
      // required: true
    }
  },
  data () {
    return {
      message: ''
    }
  },
  created () {},
  methods: {
    async onPost () {
      const body = {
        article_id:this.articleId,
        content:this.message
      }
      const res = await addComment(body)
      if(!res) return console.log('发布评论失败');
      console.log('发布评论成功');
      this.message = ''
      bus.$emit('postOk')
    }
  }
}
</script>
<style lang="scss" scoped>
.post-comment{
  padding:14px;
  display:flex;
  align-items: center;
}
.van-cell::after {
    border-bottom: none;
}
</style>
